package com.mstore.dao;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringUtils;

import com.mstore.pojo.Balance;
import com.mstore.util.CalendarUtil;

public class BalanceDao extends SuperDao {

	public void addBalance(Balance balance) {
		super.save(balance);
	}

	/**
	 * 根据shop和account来查询
	 * 
	 * @param index
	 * @param balance
	 * @return
	 */
	public List<Object> getBalancePage(int index, Balance balance) {
		/*
		 * String hbl = "from Balance where shopId = " + balance.getShopId() +
		 * " and eaId = " + balance.getEaId() + " order by createTime desc";
		 * return findPage(index, hbl);
		 */

		StringBuilder sb = new StringBuilder();
		sb.append("from Balance where shopId = ");
		sb.append(balance.getShopId());
		sb.append(" and eaId = ");
		sb.append(balance.getEaId());
		sb.append(" order by createTime desc");
		return findPage(index, sb.toString());
	}

	/**
	 * 根据时间查询
	 */
	public List<Object> getBalancePageByTime(int index, Balance balance,
			String beginTime, String endTime) {
		/*
		 * String hql = "from Balance where shopId = " + balance.getShopId() +
		 * " and eaId = " + balance.getEaId() + " order by createTime desc";
		 */

		StringBuilder sb = new StringBuilder();
		sb.append("from Balance where shopId = ");
		sb.append(balance.getShopId());
		sb.append(" and eaId = ");
		sb.append(balance.getEaId());
		/* sb.append(" order by createTime desc"); */

		if (beginTime != null && endTime != null && !beginTime.equals("")
				&& !endTime.equals("")) {
			/*
			 * hql = "from Balance where shopId = " + balance.getShopId() +
			 * " and eaId = " + balance.getEaId() +
			 * " and  createTime  between '" + beginTime + "'   and  ' " +
			 * endTime + " '" + " order by createTime desc";
			 */
			sb.append(" and  createTime  between '");
			sb.append(beginTime);
			sb.append("' and '");
			sb.append(endTime);
			sb.append("'");
		}
		sb.append(" order by createTime desc");
		return findPage(index, sb.toString());
	}

	public List<Object> getBalancePageByTimeTotal(Balance balance,
			String beginTime, String endTime) {
		/*
		 * String hql = "from Balance where shopId = " + balance.getShopId() +
		 * " and eaId = " + balance.getEaId() + " order by createTime desc";
		 */

		StringBuilder sb = new StringBuilder();
		sb.append("from Balance where shopId = ");
		sb.append(balance.getShopId());
		sb.append(" and eaId = ");
		sb.append(balance.getEaId());
		/* sb.append(" order by createTime desc"); */

		if (beginTime != null && endTime != null && !beginTime.equals("")
				&& !endTime.equals("")) {
			/*
			 * hql = "from Balance where shopId = " + balance.getShopId() +
			 * " and eaId = " + balance.getEaId() +
			 * " and  createTime  between '" + beginTime + "'   and  ' " +
			 * endTime + " '" + " order by createTime desc";
			 */

			sb.append(" and  createTime  between '");
			sb.append(beginTime);
			sb.append("' and '");
			sb.append(endTime);
			sb.append("'");
		}
		sb.append(" order by createTime desc");
		return find(sb.toString());
	}

	/**
	 * 根据时间段查询
	 */
	public List<Object> getBalancePageConsumeByTime(Balance balance,
			String beginTime, String endTime) {
		/*
		 * String hql = "from Balance where shopId = " + balance.getShopId() +
		 * " and eaId = " + balance.getEaId() + " and  createTime  between '" +
		 * beginTime + "'   and  ' " + endTime + " '" +
		 * " order by createTime desc"; return find(hql);
		 */

		StringBuilder sb = new StringBuilder();
		sb.append("from Balance where shopId=");
		sb.append(balance.getShopId());
		sb.append("and eaId = ");
		sb.append(balance.getEaId());
		sb.append("and createTime between '");
		sb.append(beginTime);
		sb.append("' and '");
		sb.append(endTime);
		sb.append("' order by createTime desc");
		return find(sb.toString());
	}

	/**
	 * 根据shop和account来查询总页数
	 * 
	 * @param index
	 * @param balance
	 * @return
	 */
	public List<Object> getBalancePageTotal(Balance balance) {
		/*
		 * String hql = "from Balance where shopId = " + balance.getShopId() +
		 * " and eaId = " + balance.getEaId() + " order by createTime desc";
		 * return super.find(hql);
		 */

		StringBuilder sb = new StringBuilder();
		sb.append("from Balance where shopId = ");
		sb.append(balance.getShopId());
		sb.append(" and eaId = ");
		sb.append(balance.getEaId());
		sb.append(" order by createTime desc");
		return super.find(sb.toString());
	}

	public List<Object> getEnterpriseBalancePage(int index, Balance balance) {
		/*
		 * String hbl = "from Balance where eaId = " + balance.getEaId() +
		 * " order by createTime desc"; return findPage(index, hbl);
		 */

		StringBuilder sb = new StringBuilder();
		sb.append("from Balance where eaId = ");
		sb.append(balance.getEaId());
		sb.append(" order by createTime desc");
		return findPage(index, sb.toString());
	}

	public List<Object> getOneBalancePage(int index, Balance balance) {
		/*
		 * String hbl = "from Balance where shopId = " + balance.getShopId() +
		 * " and eaId = " + balance.getEaId() + " and memberId = " +
		 * balance.getMemberId() + " order by createTime desc"; return
		 * findPage(index, hbl);
		 */

		StringBuilder sb = new StringBuilder();
		sb.append("from Balance where shopId =  ");
		sb.append(balance.getShopId());
		sb.append(" and eaId = ");
		sb.append(balance.getEaId());
		sb.append(" and memberId = ");
		sb.append(balance.getMemberId());
		sb.append(" order by createTime desc");
		return findPage(index, sb.toString());
	}

	public List<Object> getBalancePageByMobileAndShop(int index, Balance balance) {
		/*
		 * String hbl = "from Balance where shopId = " + balance.getShopId() +
		 * " and eaId = " + balance.getEaId() + " and memberMobile = " +
		 * balance.getMemberMobile() + " order by createTime desc"; return
		 * findPage(index, hbl);
		 */

		StringBuilder sb = new StringBuilder();
		sb.append("from Balance where shopId = ");
		sb.append(balance.getShopId());
		sb.append(" and eaId = ");
		sb.append(balance.getEaId());
		sb.append(" and memberMobile = ");
		sb.append(balance.getMemberMobile());
		sb.append(" order by createTime desc");
		return findPage(index, sb.toString());
	}

	public List<Object> getEnterpriseOneBalancePage(int index, Balance balance) {
		/*
		 * String hbl = "from Balance where eaId = " + balance.getEaId() +
		 * " and memberId = " + balance.getMemberId() +
		 * " order by createTime desc"; return findPage(index, hbl);
		 */

		StringBuilder sb = new StringBuilder();
		sb.append("from Balance where eaId = ");
		sb.append(balance.getEaId());
		sb.append(" and memberId = ");
		sb.append(balance.getMemberId());
		sb.append(" order by createTime desc");
		return findPage(index, sb.toString());

	}

	public List<Object> getBalancePageByMoble(int index, Balance balance) {
		/*
		 * String hbl = "from Balance where eaId = " + balance.getEaId() +
		 * " and memberMobile = " + balance.getMemberMobile() +
		 * " order by createTime desc"; return findPage(index, hbl);
		 */

		StringBuilder sb = new StringBuilder();
		sb.append("from Balance where eaId = ");
		sb.append(balance.getEaId());
		sb.append(" and memberMobile = ");
		sb.append(balance.getMemberMobile());
		sb.append(" order by createTime desc");
		return findPage(index, sb.toString());
	}

	/**
	 * 通过eaid和memberid查询会员充值记录
	 * 
	 * @param balance
	 * @return
	 */
	public List<Object> getBalanceByEaIdAndMemberId(Balance balance) {
		/*
		 * String hbl = "from Balance where eaId = " + balance.getEaId() +
		 * " and memberId = " + balance.getMemberId() +
		 * " order by createTime desc"; return super.find(hbl);
		 */

		StringBuilder sb = new StringBuilder();
		sb.append("from Balance where eaId = ");
		sb.append(balance.getEaId());
		sb.append(" and memberId = ");
		sb.append(balance.getMemberId());
		sb.append(" order by createTime desc");
		return super.find(sb.toString());
	}

	public List<Object> getBalancesBymember(Balance balance) {
		/*
		 * String sql = "from Balance where memberId=" + balance.getMemberId() +
		 * " order by createTime desc";
		 */
		StringBuilder sb = new StringBuilder();
		sb.append("from Balance where memberId= ");
		sb.append(balance.getMemberId());
		sb.append(" order by createTime desc");
		List<Object> objcts = super.find(sb.toString());
		return objcts;
	}

	public List<Object> getBalances(Balance balance) {
		/*
		 * String hbl = "from Balance where shopId = " + balance.getShopId() +
		 * " and eaId = " + balance.getEaId() + " order by createTime desc";
		 * return super.find(hbl);
		 */

		StringBuilder sb = new StringBuilder();
		sb.append("from Balance where shopId =");
		sb.append(balance.getShopId());
		sb.append(" and eaId = ");
		sb.append(balance.getEaId());
		sb.append("order by createTime desc");
		return super.find(sb.toString());
	}

	public List<Object> getEnterpriseBalances(Balance balance) {
		/*
		 * String hbl = "from Balance where eaId = " + balance.getEaId() +
		 * " order by createTime desc"; return super.find(hbl);
		 */

		StringBuilder sb = new StringBuilder();
		sb.append("from Balance where eaId =");
		sb.append(balance.getEaId());
		sb.append(" order by createTime desc");
		return super.find(sb.toString());
	}

	public List<Object> getBalancesByshop(Balance balance) {
		/*
		 * String hbl = "from Balance where memberId = " + balance.getMemberId()
		 * + " and shopId = " + balance.getShopId() +
		 * " order by createTime desc"; return super.find(hbl);
		 */

		StringBuilder sb = new StringBuilder();
		sb.append("from Balance where memberId = ");
		sb.append(balance.getMemberId());
		sb.append("and shopId = ");
		sb.append(balance.getShopId());
		sb.append(" order by createTime desc");
		return super.find(sb.toString());
	}

	public int getBalanceLine(Balance balance) {
		String sql = "from Balance where shopId = ? and eaId = ?";
		List<Object> objects = super.getObject(sql,
				new Object[] { balance.getShopId(), balance.getEaId() });
		return objects.size();
	}

	public int getEnterpriseBalanceLine(Balance balance) {
		String sql = "from Balance where eaId = ?";
		List<Object> objects = super.getObject(sql,
				new Object[] { balance.getEaId() });
		return objects.size();
	}

	public int getOneBalanceLine(Balance balance) {
		String sql = "from Balance where shopId = ? and eaId = ? and memberMobile = ?";
		List<Object> objects = super.getObject(
				sql,
				new Object[] { balance.getShopId(), balance.getEaId(),
						balance.getMemberMobile() });
		return objects.size();
	}

	public int getEnterpriseOneBalanceLine(Balance balance) {
		String sql = "from Balance where eaId = ? and memberMobile = ?";
		List<Object> objects = super.getObject(sql,
				new Object[] { balance.getEaId(), balance.getMemberMobile() });
		return objects.size();
	}

	public List<Object> getByTime(Balance balance, String beginTime,
			String endTime) {
		/* String sql = ""; */
		StringBuilder sb = new StringBuilder();
		if (balance.getMemberId() != null && beginTime.equals("")
				&& endTime.equals("")) {
			/*
			 * sql = " from Balance where  memberId=" + balance.getMemberId() +
			 * " and  shopId=" + balance.getShopId() +
			 * "order by createTime desc";
			 */
			sb.setLength(0);
			sb.append("from Balance where memberId=");
			sb.append(balance.getMemberId());
			sb.append(" and shopId=");
			sb.append(balance.getShopId());
		}
		if (beginTime != null && !beginTime.equals("") && endTime != null
				&& !endTime.equals("") && balance.getMemberId() == null) {

			/*
			 * sql = " from Balance where  shopId=" + balance.getShopId() +
			 * " and  createTime  between  '" + beginTime + "'  and  '" +
			 * endTime + "' order by createTime desc";
			 */
			sb.setLength(0);
			sb.append("from Balance where shopId = ");
			sb.append(balance.getShopId());
			sb.append(" and createTime between '");
			sb.append(beginTime);
			sb.append("' and '");
			sb.append(endTime);
			sb.append("'");
		}
		if (balance.getMemberId() != null && beginTime != null
				&& !beginTime.equals("") && endTime != null
				&& !endTime.equals("")) {
			/*
			 * sql = "from Balance where  memberId=" + balance.getMemberId() +
			 * " and  shopId=" + balance.getShopId() +
			 * " and createTime  between  '" + beginTime + "' and  '" + endTime
			 * + "'  order by createTime desc";
			 */
			sb.setLength(0);
			sb.append("from Balance where memberId = ");
			sb.append(balance.getMemberId());
			sb.append("and shopId=");
			sb.append(balance.getShopId());
			sb.append(" and createTime between '");
			sb.append(beginTime);
			sb.append("' and '");
			sb.append(endTime);
			sb.append("'");
		}
		sb.append(" order by createTime desc");
		List<Object> objects = super.find(sb.toString());
		return objects;
	}

	public int getByCreateTimeAndMemberIdPage(Balance balance,
			String beginTime, String endTime) {
		/* String sql = ""; */
		StringBuilder sb = new StringBuilder();
		if (balance.getMemberId() != null && beginTime.equals("")
				&& endTime.equals("")) {
			/*
			 * sql = " from Balance where  memberId=" + balance.getMemberId() +
			 * " and  shopId=" + balance.getShopId() +
			 * "order by createTime desc";
			 */
			sb.setLength(0);
			sb.append("from Balance where memberId = ");
			sb.append(balance.getMemberId());
			sb.append(" and shopId=");
			sb.append(balance.getShopId());
		}
		if (beginTime != null && !beginTime.equals("") && endTime != null
				&& !endTime.equals("") && balance.getMemberId() == null) {

			/*
			 * sql = " from Balance where  shopId=" + balance.getShopId() +
			 * " and  createTime  between  '" + beginTime + "'  and  '" +
			 * endTime + "' order by createTime desc";
			 */
			sb.setLength(0);
			sb.append("from Balance where shopId = ");
			sb.append(balance.getShopId());
			sb.append(" and createTime between '");
			sb.append(beginTime);
			sb.append("' and '");
			sb.append(endTime);
			sb.append("'");
		}
		if (balance.getMemberId() != null && beginTime != null
				&& !beginTime.equals("") && endTime != null
				&& !endTime.equals("")) {
			/*
			 * sql = "from Balance where  memberId=" + balance.getMemberId() +
			 * " and  shopId=" + balance.getShopId() +
			 * " and createTime  between  '" + beginTime + "' and  '" + endTime
			 * + "'  order by createTime desc";
			 */
			sb.setLength(0);
			sb.append("from Balance where memberId = ");
			sb.append(balance.getMemberId());
			sb.append(" and shopId = ");
			sb.append(balance.getShopId());
			sb.append(" and createTime between '");
			sb.append(beginTime);
			sb.append("' and '");
			sb.append(endTime);
			sb.append("'");
		}
		sb.append(" order by createTime desc");
		List<Object> objects = super.find(sb.toString());
		return objects.size();

	}

	public List<Object> getByCreateTimeAndMemberId(int index, Balance balance,
			String beginTime, String endTime) {
		/* String sql = ""; */
		StringBuilder sb = new StringBuilder();
		if (balance.getMemberId() != null && beginTime.equals("")
				&& endTime.equals("")) {
			/*
			 * sql = " from Balance where  memberId=" + balance.getMemberId() +
			 * " and  shopId=" + balance.getShopId() +
			 * "order by createTime desc";
			 */
			sb.setLength(0);
			sb.append("from Balance where memberId = ");
			sb.append(balance.getMemberId());
			sb.append(" and shopId = ");
			sb.append(balance.getShopId());
		}
		if (beginTime != null && !beginTime.equals("") && endTime != null
				&& !endTime.equals("") && balance.getMemberId() == null) {
			sb.setLength(0);
			sb.append("from Balance where shopId = ");
			sb.append(balance.getShopId());
			sb.append("and createTime between '");
			sb.append(beginTime);
			sb.append("' and '");
			sb.append(endTime);
			sb.append("'");
		}
		if (balance.getMemberId() != null && beginTime != null
				&& !beginTime.equals("") && endTime != null
				&& !endTime.equals("")) {
			/*
			 * sql = "from Balance where  memberId=" + balance.getMemberId() +
			 * " and  shopId=" + balance.getShopId() +
			 * " and createTime  between  '" + beginTime + "' and  '" + endTime
			 * + "'  order by createTime desc";
			 */
			sb.setLength(0);
			sb.append("from Balance where memberId = ");
			sb.append(balance.getMemberId());
			sb.append(" and shopId=");
			sb.append(balance.getShopId());
			sb.append(" and createTime between '");
			sb.append(beginTime);
			sb.append("' and '");
			sb.append(endTime);
			sb.append("'");
		}
		sb.append(" order by createTime desc");
		List<Object> objects = super.findPage(index, sb.toString());
		return objects;

	}

	public Object selectById(Balance balance) {
		String hql = "from Balance where id = ?";
		List<Object> object = super.getObject(hql,
				new Object[] { balance.getId() });
		if (object.size() != 0) {
			return object.get(0);
		}
		else {
			return null;
		}

	}

	/**
	 * 查询在某企业的充值记录中的会员
	 */
	public List<Long> findMemberIdFromBalance(Long eaId) {
		String sql = "SELECT DISTINCT member_id FROM log_balance WHERE ea_id = "
				+ eaId;
		Object object = super.executeSql(sql);
		@SuppressWarnings("unchecked")
		List<Object> list = (ArrayList<Object>) object;
		List<Long> memberIds = new ArrayList<Long>();
		for (Object obj : list) {
			BigInteger bi = (BigInteger) obj;
			memberIds.add(bi.longValue());
		}
		return memberIds;
	}

	public void deleteById(Balance balance) {
		super.delete(balance);
	}

	/**
	 * 查询会员在某企业的充值总数
	 */
	public Object getEabalance(Balance balance) {
		String sql = "select SUM(money) from Balance where eaId = ? and memberId=?";
		List<Object> objects = super.getObject(sql,
				new Object[] { balance.getEaId(), balance.getMemberId() });
		if (objects.size() > 0) {
			return objects.get(0);
		}
		else {
			return null;
		}
	}

	/**
	 * 查询某时间段内在企业中充值金额总量
	 */
	public Double getSumBalanceByTime(Long eaId, String begin, String end) {
		String separate = " where ";
		StringBuilder sb = new StringBuilder();
		sb.append("select sum(money) from Balance");
		if (eaId != null) {
			sb.append(separate);
			sb.append("eaId = ");
			sb.append(eaId);
			separate = " and ";
		}
		if (StringUtils.isNotBlank(begin) && StringUtils.isNotBlank(end)) {
			sb.append(separate);
			sb.append("(createTime between '");
			sb.append(begin);
			sb.append("' and '");
			sb.append(end);
			sb.append("')");
			separate = " and ";
		}

		List<Object> objs = find(sb.toString());
		if (objs.isEmpty()) {
			return 0D;
		}

		Object obj = objs.get(0);
		if (obj == null) {
			return 0D;
		}

		return (Double) obj;
	}

	/**
	 * 查询某时间段内在分店中消费金额总量
	 */
	public Double getSumBalanceByTimeAndShopId(Long shopId, String begin,
			String end) {
		String separate = " where ";
		StringBuilder sb = new StringBuilder();
		sb.append("select sum(money) from Balance");
		if (shopId != null) {
			sb.append(separate);
			sb.append("shopId = ");
			sb.append(shopId);
			separate = " and ";
		}
		if (StringUtils.isNotBlank(begin) && StringUtils.isNotBlank(end)) {
			sb.append(separate);
			sb.append("(createTime between '");
			sb.append(begin);
			sb.append("' and '");
			sb.append(end);
			sb.append("')");
			separate = " and ";
		}

		List<Object> objs = find(sb.toString());
		if (objs.isEmpty()) {
			return 0D;
		}

		Object obj = objs.get(0);
		if (obj == null) {
			return 0D;
		}

		return (Double) obj;
	}

	/**
	 * 根据搜索条件查询充值记录 分页
	 */
	public List<Object> getBalancesByRequirePage(int index, Balance balance) {
		StringBuilder sql = new StringBuilder();
		sql.append("from Balance");

		sql.append(createSqlByRequire(balance));
		
		sql.append(" order by createTime desc");

		return findPage(index, sql.toString());
	}

	/**
	 * 根据搜索条件查询充值记录，取得记录总数
	 */
	public int getBalancesByRequireCount(Balance balance) {
		StringBuilder sql = new StringBuilder();
		sql.append("select count(id) from Balance");

		sql.append(createSqlByRequire(balance));

		List<Object> list = find(sql.toString());
		if (list.isEmpty()) {
			return 0;
		}

		return ((Long) list.get(0)).intValue();
	}
	
	/**
	 * 根据搜索条件查询充值记录
	 */
	public List<Object> getBalancesByRequire(Balance balance) {
		StringBuilder sql = new StringBuilder();
		sql.append("from Balance");

		sql.append(createSqlByRequire(balance));
		
		sql.append(" order by createTime desc");

		return find(sql.toString());
	}
	
	/**
	 * * 
	 * * @param balance
	 * * @return
	 */
	private String createSqlByRequire(Balance balance) {
		String separate = " where ";
		StringBuilder sql = new StringBuilder();
		
		// 企业id
		Long eaId = balance.getEaId();
		if (eaId != null && eaId != 0 && eaId != -1) {
			sql.append(separate);
			sql.append("eaId = ");
			sql.append(eaId);
			separate = " and ";
		}
		
		// 企业名称
		String eaName = balance.getEaName();
		if (eaId != null && eaId == -1) {
			if (StringUtils.isNotBlank(eaName)) {
				sql.append(separate);
				sql.append("eaName = '");
				sql.append(eaName);
				sql.append("'");
				separate = " and ";
			}
		}
		
		// 会员手机号
		String mobile = balance.getMemberMobile();
		if (StringUtils.isNotBlank(mobile)) {
			sql.append(separate);
			sql.append("memberMobile = '");
			sql.append(mobile);
			sql.append("'");
			separate = " and ";
		}

		// 店铺id
		Long shopId = balance.getShopId();
		if (shopId != null && shopId != 0) {
			sql.append(separate);
			sql.append("shopId = ");
			sql.append(shopId);
			separate = " and ";
		}

		// 充值方式
		Integer type = balance.getType();
		if (type != null && type != 0) {
			sql.append(separate);
			sql.append("type = ");
			sql.append(type);
			separate = " and ";
		}

		// 按固定时间查询
		Integer timeType = balance.getTimeType();
		if (timeType != null && timeType != 0) {
			String begin = null;
			String end = null;
			switch (timeType) {
				case 1:
					// 本年
					begin = CalendarUtil.formatDate(CalendarUtil
							.getCurrYearFirst());
					end = CalendarUtil.formatDate(CalendarUtil
							.getCurrYearLast()) + " 23:59:59";
					break;
				case 2:
					// 本月
					begin = CalendarUtil.formatDate(CalendarUtil
							.getCurrMonthFirst());
					end = CalendarUtil.formatDate(CalendarUtil
							.getCurrMonthLast()) + " 23:59:59";
					break;
				case 3:
					// 本周
					begin = CalendarUtil.formatDate(CalendarUtil
							.getCurrWeekFirst());
					end = CalendarUtil.formatDate(CalendarUtil
							.getCurrWeekLast()) + " 23:59:59";
					break;
				case 4:
					// 今日
					begin = CalendarUtil
							.formatDate(CalendarUtil.getTodayDate());
					end = CalendarUtil.formatDate(CalendarUtil.getTodayDate())
							+ " 23:59:59";
					break;
			}
			if (begin != null && end != null) {
				sql.append(separate);
				sql.append("(createTime between '");
				sql.append(begin);
				sql.append("' and '");
				sql.append(end);
				sql.append("')");
				separate = " and ";
			}
		}
		else if (timeType != null && timeType == 0) {
			// 按自定义时间查询
			String startTime = balance.getBeginTime();
			String endTime = balance.getEndTime();

			if (StringUtils.isNotBlank(startTime)
					&& StringUtils.isNotBlank(endTime)) {
				sql.append(separate);
				sql.append("(createTime between '");
				sql.append(startTime);
				sql.append("' and '");
				sql.append(endTime);
				sql.append("')");
				separate = " and ";
			}
			else if (StringUtils.isNotBlank(startTime)) {
				sql.append(separate);
				sql.append("createTime >= '");
				sql.append(startTime);
				sql.append("'");
				separate = " and ";
			}
			else if (StringUtils.isNotBlank(endTime)) {
				sql.append(separate);
				sql.append("createTime <= '");
				sql.append(endTime);
				sql.append("'");
				separate = " and ";
			}
		}
		
		return sql.toString();
	}

}
